<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="showHide"> {{ isShow?'消失':'显示' }} </button>
    <keep-alive>
      <home v-if="isShow"></home>
    </keep-alive>
  </div>
  <script src="./vue.js"></script>
  <script>
    const Home = {
      template: `
        <div>
          home组件
          <input v-model="inputTxt"/>  
        </div>
      `,
      created(){
        console.log('实例化完成');
      },
      mounted(){
        console.log('dom渲染完成');
      },
      beforeDestroy(){
        console.log('组件马上要卸载');
      },
      activated(){
        console.log('activated触发了');
      },
      deactivated(){
        console.log('deactivated触发了');
      },
      data(){
        return {
          inputTxt: ''
        }
      }
    }
    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      },
      methods: {
        showHide(){
          this.isShow = !this.isShow;
        }
      }
    })
  </script>
</body>
</html>